Skip to content

Dev to Main Sync#2581

Merged
iamitprakash merged 2 commits intomainfrom
develop
Feb 26, 2026
Merged

Dev to Main Sync#2581
iamitprakash merged 2 commits intomainfrom
develop

Conversation

@AnujChhikara
Copy link
Contributor

@AnujChhikara AnujChhikara commented Feb 24, 2026

Date: 25 Feb 2026

Developer Name: @AnujChhikara


Issue Ticket Number

PRs going for sync

Description

  • refactor the discord invite link generate logic functionality

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screencast_from_2026-02-25_01-19-20.mp4

…dling (#2579)

* feat: enhance Discord invite generation with application-specific handling

- Added applicationId and role validation in the invite generation process.
- Updated the invite retrieval method to support application-scoped invites.
- Enhanced middleware to pass applicationId to the request object.
- Implemented tests for application-specific invite generation scenarios.

* feat: enhance Discord invite generation for super users and improve error logging
@AnujChhikara AnujChhikara self-assigned this Feb 24, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…2582)

* refactor: remove short-circuit middleware from Discord invite route

* refactor: remove commented short-circuit middleware for Discord invite routes
* Short-circuit this POST method for this endpoint
* Refer https://github.com/Real-Dev-Squad/todo-action-items/issues/269 for more details.
*/
router.get("/invite", authenticate, getUserDiscordInvite);

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.

Copilot Autofix

AI 1 day ago

In general, the fix is to add a rate-limiting middleware to the sensitive route(s) so that repeated requests from the same client (or IP) are capped within a time window. In Express, this is typically done using a library like express-rate-limit, configured with reasonable windowMs and max settings, and then passed as a middleware in the route definition.

For this file, the minimal, targeted change that preserves existing behavior is:

  • Import express-rate-limit at the top of routes/discordactions.js.
  • Define one or more limiter instances, for example inviteLimiter, configured specifically for the /invite endpoints (and optionally reuse the same limiter for both GET and POST on /invite).
  • Apply that limiter as a middleware before authenticate on the /invite routes (line 40 and 41). This ensures requests are rate-limited even if authentication fails and keeps the rest of the pipeline unchanged.
  • Leave all other routes untouched unless we want broader protection; to keep the change minimal and precisely aligned with the alert, we will limit it to the invite routes.

Concretely:

  • Add a const rateLimit = require("express-rate-limit"); near the other require calls.
  • Add a new const inviteLimiter = rateLimit({ ... }) after the imports, with a conservative configuration such as a few tens of requests per 15 minutes.
  • Update router.get("/invite", authenticate, getUserDiscordInvite); to include inviteLimiter (e.g., router.get("/invite", inviteLimiter, authenticate, getUserDiscordInvite);), and similarly for the POST /invite route.
Suggested changeset 2
routes/discordactions.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/routes/discordactions.js b/routes/discordactions.js
--- a/routes/discordactions.js
+++ b/routes/discordactions.js
@@ -31,14 +31,20 @@
 const { Services } = require("../constants/bot");
 const { verifyCronJob } = require("../middlewares/authorizeBot");
 const { authorizeAndAuthenticate } = require("../middlewares/authorizeUsersAndService");
+const rateLimit = require("express-rate-limit");
 const router = express.Router();
 
+const inviteLimiter = rateLimit({
+  windowMs: 15 * 60 * 1000, // 15 minutes
+  max: 50, // limit each IP to 50 invite requests per windowMs
+});
+
 router.post("/groups", authenticate, checkIsVerifiedDiscord, validateGroupRoleBody, createGroupRole);
 router.get("/groups", authenticate, checkIsVerifiedDiscord, validateLazyLoadingParams, getPaginatedAllGroupRoles);
 router.delete("/groups/:groupId", authenticate, checkIsVerifiedDiscord, authorizeRoles([SUPERUSER]), deleteGroupRole);
 router.post("/roles", authenticate, checkIsVerifiedDiscord, validateMemberRoleBody, addGroupRoleToMember);
-router.get("/invite", authenticate, getUserDiscordInvite);
-router.post("/invite", authenticate, checkCanGenerateDiscordLink, generateInviteForUser);
+router.get("/invite", inviteLimiter, authenticate, getUserDiscordInvite);
+router.post("/invite", inviteLimiter, authenticate, checkCanGenerateDiscordLink, generateInviteForUser);
 
 router.delete("/roles", authenticate, checkIsVerifiedDiscord, deleteRole);
 router.get("/roles", authenticate, checkIsVerifiedDiscord, getGroupsRoleId);
EOF
@@ -31,14 +31,20 @@
const { Services } = require("../constants/bot");
const { verifyCronJob } = require("../middlewares/authorizeBot");
const { authorizeAndAuthenticate } = require("../middlewares/authorizeUsersAndService");
const rateLimit = require("express-rate-limit");
const router = express.Router();

const inviteLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 50, // limit each IP to 50 invite requests per windowMs
});

router.post("/groups", authenticate, checkIsVerifiedDiscord, validateGroupRoleBody, createGroupRole);
router.get("/groups", authenticate, checkIsVerifiedDiscord, validateLazyLoadingParams, getPaginatedAllGroupRoles);
router.delete("/groups/:groupId", authenticate, checkIsVerifiedDiscord, authorizeRoles([SUPERUSER]), deleteGroupRole);
router.post("/roles", authenticate, checkIsVerifiedDiscord, validateMemberRoleBody, addGroupRoleToMember);
router.get("/invite", authenticate, getUserDiscordInvite);
router.post("/invite", authenticate, checkCanGenerateDiscordLink, generateInviteForUser);
router.get("/invite", inviteLimiter, authenticate, getUserDiscordInvite);
router.post("/invite", inviteLimiter, authenticate, checkCanGenerateDiscordLink, generateInviteForUser);

router.delete("/roles", authenticate, checkIsVerifiedDiscord, deleteRole);
router.get("/roles", authenticate, checkIsVerifiedDiscord, getGroupsRoleId);
package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -42,7 +42,8 @@
     "passport-github2": "0.1.12",
     "passport-google-oauth20": "^2.0.0",
     "rate-limiter-flexible": "5.0.3",
-    "winston": "3.13.0"
+    "winston": "3.13.0",
+    "express-rate-limit": "^8.2.1"
   },
   "devDependencies": {
     "@types/chai": "4.3.16",
EOF
@@ -42,7 +42,8 @@
"passport-github2": "0.1.12",
"passport-google-oauth20": "^2.0.0",
"rate-limiter-flexible": "5.0.3",
"winston": "3.13.0"
"winston": "3.13.0",
"express-rate-limit": "^8.2.1"
},
"devDependencies": {
"@types/chai": "4.3.16",
This fix introduces these dependencies
Package Version Security advisories
express-rate-limit (npm) 8.2.1 None
Copilot is powered by AI and may make mistakes. Always verify output.
@iamitprakash iamitprakash merged commit e20fe20 into main Feb 26, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants